package com.example.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.demo.R;
import com.example.demo.entity.Game;
import com.example.demo.entity.Goods;

import java.util.ArrayList;
import java.util.List;

public class GameAdapter extends RecyclerView.Adapter<GameAdapter.GameHolder> {
    private Context context ;
    private List<Game> gameList = new ArrayList<>();;

    public GameAdapter() {
    }

    public void setData(List<Game> gameList){
        this.gameList = gameList;
    }

    @NonNull
    @Override
    public GameHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_game, parent, false);
        return new GameHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GameHolder holder, int position) {
        Game game = gameList.get(position);
        holder.img.setImageResource(game.getImg());
        holder.tvDownloadCount.setText(game.getCount());
        holder.tvInstall.setText(game.getInstall());
        holder.tvName.setText(game.getName());
        holder.tvRank.setText(game.getRank());
        holder.tvSize.setText(game.getSize());
    }

    @Override
    public int getItemCount() {
        return gameList == null ? 0 : gameList.size();
    }

    public class GameHolder extends RecyclerView.ViewHolder {

        TextView tvRank;
        TextView tvName;
        TextView tvDownloadCount;
        TextView tvSize;
        TextView tvInstall;
        ImageView img;

        public GameHolder(@NonNull View itemView) {
            super(itemView);

            tvRank = itemView.findViewById(R.id.tv_rank);
            tvName = itemView.findViewById(R.id.tv_name);
            tvDownloadCount = itemView.findViewById(R.id.tv_download_count);
            tvSize = itemView.findViewById(R.id.tv_size);
            tvInstall = itemView.findViewById(R.id.install);
            img = itemView.findViewById(R.id.img);
        }
    }
}
